package com.lefevre.cms.service.feedback.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lefevre.cms.bean.feedback.Feedback;
import com.lefevre.cms.mapper.FeedbackMapper;
import com.lefevre.cms.service.feedback.FeedbackService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 在线留言
 *
 * @author Lefevre
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {

    /**
     * 根据Id查询留言
     *
     * @param feedbackId 留言Id
     * @return
     */
    @Override
    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    public Feedback findById(Long feedbackId) {
        return baseMapper.selectById(feedbackId);
    }

    /**
     * 保存留言
     *
     * @param feedback
     */
    public void saveFeedback(Feedback feedback) {
        baseMapper.insert(feedback);
    }


    /**
     * 修改留言
     *
     * @param feedback
     * @return
     */
    @Override
    public Integer updateFeedback(Feedback feedback) {
        return baseMapper.updateById(feedback);
    }

    /**
     * 删除留言
     *
     * @param feedbackId 留言Id
     */
    public Integer deleteFeedback(Long feedbackId) {
        return baseMapper.deleteById(feedbackId);
    }

    /**
     * 查询留言数量
     *
     * @return
     */
    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    public Long feedbackCount() {
        return baseMapper.selectCount(null);
    }
}
